import { reqOrderList } from '../../../api/order'
Page({
  // 页面的初始数据
  data: {
    orderList: [],
    page: 1, // 页码
    limit: 10, // 每页展示的条数
    total: 0, // 订单列表总条数
    isLoading: false // 数据等待
  },
  async getOrderList() {
    this.data.isLoading = true
    const { page, limit } = this.data
    const res = await reqOrderList(page, limit)
    this.data.isLoading = false
    if (res.code === 200) {
      this.setData({
        orderList: [...this.data.orderList, ...res.data.records],
        total: res.data.total
      })
    }
  },
  onLoad(options) {
    this.getOrderList()
  },
  onReachBottom() {
    const { isLoading, total, orderList, page } = this.data
    if (isLoading) return
    if (total === orderList.length) {
      return wx.toast({
        title: '数据加载完毕'
      })
    }
    this.setData({
      page: page + 1
    })
    this.getOrderList()
  }
})
